package com.xja.service.impl;/**
 * @className: RoleServiceImpl
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/8
 **/

import com.xja.mapper.RolesMapper;
import com.xja.pojo.Role;
import com.xja.service.RoleService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName : RoleServiceImpl  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/8  10:04
 */
//增删改事务处理
//@Transactional(propagation = Propagation.REQUIRED)
//查询 （只读）
//@Transactional(readOnly = true)
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RolesMapper rolesMapper;

    @Transactional(readOnly = true)
    @Override
    public List<Role> getRolesListByAid(Integer aId) {
        return rolesMapper.selectRolesByAdmin(aId);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Role> getRolesList() {
        return rolesMapper.selectRoles();
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void updateRoles(Integer[] roles, Integer aid) {
        int i = rolesMapper.deleteRolesByAid(aid);
        if(roles.length!=0&&roles!=null) {
            for (Integer role : roles) {
                rolesMapper.insertRoles(role, aid);
            }
        }
    }
    @Transactional(readOnly = true)
    @Override
    public Role getRoleByRid(Integer rid) {
        return rolesMapper.selectByPrimaryKey(rid);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void addRole(Role roles) {
        rolesMapper.insert(roles);
    }
}
